package com.changgou.goods.dao;
import com.changgou.goods.pojo.Sku;
import com.changgou.order.pojo.OrderItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

/****
 * @Author:itheima
 * @Description:Sku的Dao
 *****/
public interface SkuMapper extends Mapper<Sku> {
    /**
     * 结算商品之后,减少库存,卖出数量+
     */
    @Update("UPDATE tb_sku SET num =num -#{num},sale_num = sale_num+#{num} where id = #{skuId} and num>=#{num}")
    Integer reduceCount(@Param("skuId") String skuId,@Param("num") Integer num);

    /**
     * 回滚库存 库存数量+ 卖出数量 -
     * @param skuId
     * @param num
     * @return
     */
    @Update("update tb_sku set num = num+#{num},sale_num=sale_num-#{num} where id = #{skuId}")
    Integer skuNumRollback(@Param("skuId") String skuId,@Param("num") Integer num);
}
